package aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import util.BaseUtil;
import vo.Store;

@Aspect
@Component
public class common {
	private final String loginPc="execution(* service.LoginService.login(..))";
	private final String registPc="execution(* service.LoginService.regist(..))";
	private final String addGoodsPc="execution(* service.GoodsService.insertGoods(..))";
	private final String querryAllGoodsPC="execution(* service.GoodsService.queryAllGoods(..))";
	@Around(loginPc)
	public Object loginPcProcess(ProceedingJoinPoint jp){
		Object o=null;
		String psd=(String) jp.getArgs()[1];
		try {
			o=jp.proceed(new Object[]{jp.getArgs()[0],BaseUtil.JohnMd(psd,"md5")});
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}
	@Around(registPc)
	public Object registPcProcess(ProceedingJoinPoint jp){
		Object o=null;
		Store sp=(Store) jp.getArgs()[0];
		sp.setPassword(BaseUtil.JohnMd(sp.getPassword(),"md5"));
		try {
			o=jp.proceed();
		} catch (Throwable e) {
			e.printStackTrace();
		}
		return o;
	}
	@Around(addGoodsPc)
	public Object addGoodsPcProcess(ProceedingJoinPoint jp){
		Object o=null;
		try {
			o=jp.proceed();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}
	@Around(querryAllGoodsPC)
	public Object querryAllGoodsPCProcess(ProceedingJoinPoint jp){
		Object o=null;
		try {
			o=jp.proceed();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}
}
